import request from './request.js'

// 课程相关接口
export const courseApi = {
  // 获取课程列表
  getCourseList(params) {
    return request({
      url: '/api/course/list/page',
      method: 'GET',
      data: {
        ...params,
        sortField: 'createTime',
        sortOrder: 'desc'
      }
    })
  },

  // 获取课程详情
  getCourseDetail(id) {
    return request({
      url: `/api/course/get`,
      method: 'GET',
      data: { id }
    })
  },

  // 报名课程
  enrollCourse(id) {
    return request({
      url: '/api/course/enroll',
      method: 'POST',
      data: id 
    })
  },

  // 获取章节内容
  getChapterContent(courseId, chapter) {
    return request({
      url: '/api/course/chapter',
      method: 'GET',
      data: { 
        id: courseId,
        chapter 
      }
    })
  },

  // AI 对话
  chatWithAI(message) {
    return request({
      url: '/api/AI',
      method: 'POST',
      data: {
        message:message
      }
    })
  },
  // 保存观看记录
  saveWatchRecord(courseId, chapterId, duration) {
    return request({
      url: '/api/course/watch/record',
      method: 'POST',
      data: {
				courseId: courseId,
				chapterId: chapterId,
				duration: duration
			}
    })
  },

  // 获取观看统计
  getWatchStats() {
    return request({
      url: '/api/course/watch/stats',
      method: 'GET'
    })
  },

  // 获取推荐课程
  getRecommendCourses: () => {
    return request({
      url: '/api/course/watch/recommend',
      method: 'GET'
    })
  }
} 

// 用户相关接口
export const userApi = {
  // ... 其他接口

  // 退出登录
  logout() {
    return request({
      url: '/api/user/logout',
      method: 'POST'
    })
  }
} 

// 获取应用详情
export async function getAppVoById(id) {
  return request({
    url: '/api/app/get/vo?id=' + id,
    method: 'GET',
  });
}